package com.tianyi.controller.pictureAlbum;

import com.tianyi.controller.BaseController;
import com.tianyi.controller.menu.MenuController;
import com.tianyi.lib.model.WebResult;
import com.tianyi.lib.req.PictureAlbumReq;
import com.tianyi.lib.req.QueryPage;
import com.tianyi.model.SimpleLoginUser;
import com.tianyi.pictureAlbum.PictureAlbumService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author oh_grd
 */
@RestController
@RequestMapping("pictureAlbum")
public class PictureAlbumController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(MenuController.class);

    @Autowired
    private PictureAlbumService pictureAlbumService;

    @RequestMapping(value = "addPictureAlbum", method = RequestMethod.POST)
    public WebResult<?> addPictureAlbum(@RequestBody PictureAlbumReq pictureAlbumReq) {
        System.out.println("req first: "+pictureAlbumReq.toString());
        SimpleLoginUser loginUser = getUserFromRequest();
        if (loginUser == null){
            return WebResult.error("login user is null");
        }
        return pictureAlbumService.addPictureAlbum(pictureAlbumReq);
    }

    @RequestMapping(value = "editPictureAlbumById", method = RequestMethod.POST)//根据Id进行整行所有Id之外字段的修改
    public WebResult<?> editPictureAlbum(@RequestBody PictureAlbumReq pictureAlbumReq) {
        SimpleLoginUser loginUser = getUserFromRequest();
        if (loginUser == null){
            return WebResult.error("login user is null");
        }
        return pictureAlbumService.editPictureAlbumById(pictureAlbumReq);
    }

    @RequestMapping(value = "editPictureAlbumByIdSelectively", method = RequestMethod.POST)//传哪些非Id字段就改哪些非Id字段，选择性的
    public WebResult<?> editPictureAlbumSelectively(@RequestBody PictureAlbumReq pictureAlbumReq) {
        SimpleLoginUser loginUser = getUserFromRequest();
        if (loginUser == null){
            return WebResult.error("login user is null");
        }
        return pictureAlbumService.editPictureAlbumByIdSelectively(pictureAlbumReq);
    }

    @RequestMapping(value = "deletePictureAlbumById", method = RequestMethod.POST)
    public WebResult<?> deletePictureAlbumById(@RequestBody PictureAlbumReq pictureAlbumReq) {
        SimpleLoginUser loginUser = getUserFromRequest();
        if (loginUser == null){
            return WebResult.error("login user is null");
        }
        return pictureAlbumService.deletePictureAlbumById(pictureAlbumReq);
    }

    @RequestMapping(value = "queryPictureAlbumsByPage", method = RequestMethod.POST)
    public WebResult<?> queryPictureAlbumByPage(@RequestBody QueryPage queryPage) {
        SimpleLoginUser loginUser = getUserFromRequest();
        if (loginUser == null){
            return WebResult.error("login user is null");
        }
        return pictureAlbumService.queryPictureAlbumByPage(queryPage);
    }
}
